@import '../../styles/themes/default.less';

.rk-loading {
  position: relative;
  color: @loading-spinner-color;
  font-size: 0;
  vertical-align: middle;

  &__spinner {
    position: relative;
    display: inline-block;
    width: @loading-spinner-size;
    // compatible for 1.x, users may set width or height in root element
    max-width: 100%;
    height: @loading-spinner-size;
    max-height: 100%;
    vertical-align: middle;
    animation: rk-rotate @loading-spinner-animation-duration linear infinite;

    &--spinner {
      animation-timing-function: steps(12);

      i {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;

        &::before {
          display: block;
          width: 2px;
          height: 25%;
          margin: 0 auto;
          background-color: currentColor;
          border-radius: 40%;
          content: ' ';
        }
      }
    }

    &--circular {
      animation-duration: 2s;
    }

    &--ball {
      animation: none;
    }
  }

  &__circular {
    display: block;
    width: 100%;
    height: 100%;

    circle {
      animation: rk-circular 1.5s ease-in-out infinite;
      stroke: currentColor;
      stroke-width: 3;
      stroke-linecap: round;
    }
  }

  &__text {
    display: inline-block;
    margin-left: @padding-xs;
    color: @loading-text-color;
    font-size: @loading-text-font-size;
    vertical-align: middle;
  }

  &--vertical {
    display: flex;
    flex-direction: column;
    align-items: center;

    .rk-loading__text {
      margin: @padding-xs 0 0;
    }
  }

  &__ball {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    height: 100%;
    transform: translateZ(0) scale(1);
    transform-origin: 0 0; /* see note above */
    backface-visibility: hidden;

    div {
      position: absolute;
      box-sizing: content-box;
      width: 12px;
      height: 12px;
      border-radius: 50%;
    }
    div:nth-child(1) {
      background: #448aff;
      animation: rk-ball--right 1s linear infinite;
      animation-delay: -0.5s;
    }
    div:nth-child(2) {
      background: #ef5350;
      animation: rk-ball--right 1s linear infinite;
      animation-delay: 0s;
    }
    div:nth-child(3) {
      background: #448aff;
      animation: rk-ball 1s linear infinite;
      animation-delay: -0.5s;
    }
  }
}

@keyframes rk-ball {
  0% {
    transform: translate(0 0);
    opacity: 1;
  }
  49.99% {
    transform: translate(24px, 0);
    opacity: 1;
  }
  50% {
    transform: translate(24px, 0);
    opacity: 0;
  }
  100% {
    transform: translate(0, 0);
    opacity: 0;
  }
}
@keyframes rk-ball--right {
  0% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(24px, 0);
  }
  100% {
    transform: translate(0, 0);
  }
}

/* generated by https://loading.io/ */

@keyframes rk-circular {
  0% {
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
  }

  50% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -40;
  }

  100% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -120;
  }
}

.generate-spinner(@n, @i: 1) when (@i =< @n) {
  .rk-loading__spinner--spinner i:nth-of-type(@{i}) {
    transform: rotate(@i * 30deg);
    opacity: 1 - (0.75 / 12) * (@i - 1);
  }
  .generate-spinner(@n, (@i + 1));
}
.generate-spinner(12);
